//
//  ZGLMatchsCell.m
//  ZeegingLottery
//
//  Created by 李曌 on 2018/10/22.
//  Copyright © 2018 蒂埃里. All rights reserved.
//

#import "ZGLMatchsCell.h"
#import "ZZGradientProgress.h"

@interface ZGLMatchsCell()

@property (weak, nonatomic) IBOutlet UIView *ArcDataBG;

@property (weak, nonatomic) IBOutlet UIView *colorTips;//颜色

@property (weak, nonatomic) IBOutlet UIImageView *HomeTeamIcon;

@property (weak, nonatomic) IBOutlet UIImageView *AwayTeamIcon;

@property (weak, nonatomic) IBOutlet UIImageView *WeatherImage;

@property (weak, nonatomic) IBOutlet UILabel *MatchDate;

@property (weak, nonatomic) IBOutlet UILabel *Return;//最高回报

@property (weak, nonatomic) IBOutlet UILabel *HomeTeamName;

@property (weak, nonatomic) IBOutlet UILabel *AwayTeamName;

@property (weak, nonatomic) IBOutlet UILabel *MatchTime;

@property (weak, nonatomic) IBOutlet UILabel *PredictedLabel;//预测结果

@property (weak, nonatomic) IBOutlet UILabel *IsPlaying; //赛事状态

@property (weak, nonatomic) IBOutlet UILabel *Probability;

@property (weak, nonatomic) IBOutlet UILabel *home;

@property (weak, nonatomic) IBOutlet UILabel *away;
@property (weak, nonatomic) IBOutlet UILabel *Results;
@property (weak, nonatomic) IBOutlet UILabel *yuceGaiLv;




@property (nonatomic, strong) ZZGradientProgress *ArcData; //比例弧形


@end


@implementation ZGLMatchsCell

+ (instancetype)xibMatchsCell
{
    return [[[NSBundle mainBundle] loadNibNamed:@"ZGLMatchsCell" owner:nil options:nil]lastObject];;
    
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        
        
        [HKUIUtils addLineInView:self.contentView color:BorderColor top:NO leftMargin:0 rightMargin:0];

    }
    return self;
}

#pragma mark - setter&getter

-(ZZGradientProgress *)ArcData
{
    if (!_ArcData) {
        _ArcData = [[ZZGradientProgress alloc] initWithFrame:CGRectMake(0, 0, 55, 55) startColor:[UIColor orangeColor] endColor:[UIColor redColor] startAngle:-90 reduceAngle:0 strokeWidth:2.5];
        _ArcData.animationDuration = 1;
        _ArcData.animationSameTime = NO;
        _ArcData.showProgressText = NO;
    }
    return _ArcData;
}

//cell内边距
- (void)setFrame:(CGRect)frame{
//    frame.origin.x += 10;
    frame.origin.y += 5;
    frame.size.height -= 5;
//    frame.size.width -= 20;
    [super setFrame:frame];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.HomeTeamName.font = kFONT_SIZE(13);
    self.AwayTeamName.font = kFONT_SIZE(13);
    self.MatchDate.font = kFONT_SIZE(13);
    self.Return.font = kFONT_SIZE(13);
    self.MatchTime.font = kFONT_SIZE(13);
    self.Results.font = kFONT_SIZE(10);
    self.yuceGaiLv.font = [UIFont systemFontOfSize:8];
    self.home.font = kFONT_SIZE(13);
    self.away.font = kFONT_SIZE(13);
    self.PredictedLabel.font = kFONT_SIZE(13);
    
}

- (void)setModel:(ZGLMatchModel *)model
{
    _model = model;
    NSString *imageHeader = @"http://betcat.zeeging.com";
    //未开赛
    self.IsPlaying.text = model.statustips;
    
    //颜色tips
    self.colorTips.backgroundColor = [PublicMethod colorFromHex:model.color];
    
    //联赛&时间
    NSString *matchDateSrt = [NSString stringWithFormat:@"%@ %@",model.leaguenameabbr,model.matchkeycn];
    self.MatchDate.text = matchDateSrt;
    
    //主队
    self.HomeTeamName.text = model.homename;
    NSString *homeImageUrl = [NSString stringWithFormat:@"%@%@",imageHeader,model.homelogo];
    [self.HomeTeamIcon sd_setImageWithURL:[NSURL URLWithString:homeImageUrl] placeholderImage:[UIImage imageNamed:@"teamLogo_default"]];
    
    //客队
    self.AwayTeamName.text = model.awayname;
    NSString *awayImageUrl = [NSString stringWithFormat:@"%@%@",imageHeader,model.awaylogo];
    [self.AwayTeamIcon sd_setImageWithURL:[NSURL URLWithString:awayImageUrl] placeholderImage:[UIImage imageNamed:@"teamLogo_default"]];
    
    //回报
    self.Return.text = model.connertips;
    
    //预测赛果
    self.PredictedLabel.text = [self setPredictedWith:model.predict];
    
    //比赛时间
    self.MatchTime.text = model.matchtime;
    
    //天气
    NSURL *WeatherUrl = [NSURL URLWithString:model.weathericon];
    [self.WeatherImage sd_setImageWithURL:WeatherUrl placeholderImage:[UIImage imageNamed:@"cloudy.png"]];
    
    //预测概率
    [self drawArcDataWith:model.probility];
    self.Probability.text = [NSString stringWithFormat:@"%ld",model.probility];
}


- (void)drawArcDataWith:(NSInteger )data 
{
    float num = (float)data/100;
    self.ArcData.progress = num;
    [self.ArcDataBG addSubview:self.ArcData];

}

//取预测赛果
- (NSString *)setPredictedWith:(NSArray *)array
{
    NSString *str = [NSString string];
    for (NSDictionary *dict in array) {
        
        NSString *string = dict[@"title"];
        str = [str stringByAppendingString:string];
    }
    return str;
}




@end
